#!/usr/bin/env python
#
#       Options.py
#       
#       Copyright 2009 Ben Davis <its.hip@gmail.com>, Pete Lord <mr.petelord@gmail.com>, Robin Hayes <bonzairob@hotmail.co.uk>
#       
#       This program is free software; you can redistribute it and/or modify
#       it under the terms of the GNU General Public License as published by
#       the Free Software Foundation; either version 2 of the License, or
#       (at your option) any later version.
#       
#       This program is distributed in the hope that it will be useful,
#       but WITHOUT ANY WARRANTY; without even the implied warranty of
#       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#       GNU General Public License for more details.
#       
#       You should have received a copy of the GNU General Public License
#       along with this program; if not, write to the Free Software
#       Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
#       MA 02110-1301, USA.


def write():
    output = open('options.cfg', 'w')
    output.write(("SCREEN_WIDTH="+str(SCREEN_WIDTH)+" \n"+\
    "SCREEN_HEIGHT="+str(SCREEN_HEIGHT)+" \n"+\
    "FULLSCREEN="+str(FULLSCREEN)+" \n"+\
    " \n"+\
    "ANIMATION_DIVISIONS="+str(ANIMATION_DIVISIONS)+" \n"+\
    " \n"+\
    "MESSAGEBOX_TIMEOUT="+str(MESSAGEBOX_TIMEOUT)+" \n"+\
    " \n"+\
    "SHIPINFO_ON_HOVER="+str(SHIPINFO_ON_HOVER)+" \n"+\
    "SHIPINFO_ON_SELECT="+str(SHIPINFO_ON_SELECT)+" \n"+\
    "PAN_ON_SELECT="+str(PAN_ON_SELECT)+" \n"+\
    "SELECT_WHEN_NO_STEAM="+str(SELECT_WHEN_NO_STEAM)+" \n"+\
    " \n"+\
    "HIGHLIGHT_ALPHA="+str(HIGHLIGHT_ALPHA)+" \n"+\
    " \n"+\
    "KEY_SCROLL="+str(KEY_SCROLL)+" \n"+\
    "MOUSE_SCROLL="+str(MOUSE_SCROLL)+" \n"+\
    " \n"+\
    "SHADOWS="+str(SHADOWS)+" \n"+\
    " \n"+\
    "MOVEMENT_ANIMATION="+str(MOVEMENT_ANIMATION)+" \n"+\
    "PATHS_DRAWN="+str(PATHS_DRAWN)+" \n"+\
    " \n"+\
    "VOLUME_SFX="+str(VOLUME_SFX)+" \n"+\
    "VOLUME_MUSIC="+str(VOLUME_MUSIC)+" \n"+\
    "SOUND="+str(SOUND)+" \n"+\
    " \n"+\
    "AUTOLOGIN="+str(AUTOLOGIN)+" \n"+\
    "USERNAME=\""+USERNAME+"\" \n"+\
    "PASSWORD=\""+PASSWORD+"\""))
    output.close()

try:
    input = open('options.cfg', 'r')
    S = input.read()
    if S == "":
        raise IOError
    input = open('options.cfg', 'r')
    lines = input.readlines()
    for line in lines:
        exec(line)
    #risky? :/
except IOError:
    print "Options file not found or corrupt"
    #defaults plz
    
    SCREEN_WIDTH = 800  
    SCREEN_HEIGHT = 600
    FULLSCREEN = 0
    
    ANIMATION_DIVISIONS = 20

    MESSAGEBOX_TIMEOUT = 200

    SHIPINFO_ON_HOVER = True
    SHIPINFO_ON_SELECT = True
    PAN_ON_SELECT = True
    SELECT_WHEN_NO_STEAM = True

    HIGHLIGHT_ALPHA = 50

    KEY_SCROLL = 8
    MOUSE_SCROLL = 10

    SHADOWS = False

    MOVEMENT_ANIMATION = True
    PATHS_DRAWN = False

    VOLUME_SFX = 1.0
    VOLUME_MUSIC = 0.7
    SOUND = False

    AUTOLOGIN = True
    USERNAME = ""
    PASSWORD = ""
    
    write()
    #set all variables to default and write the file out.


ZOOM_LEVEL = 1 # default zoom level
TILE_WIDTH = [256, 128, 64, 32] # NECESSARY FOR ENGINE TO WORK.
TILE_HEIGHT = [128, 64, 32, 32] # "        "       "   "   ".
SPRITE_SIZE = [256, 128, 64, 32]

ZOOM_MOD = [3, 2, 1, 1]


